package entity;

import java.io.IOException;

import java.util.ArrayList;
import java.util.Iterator;

import settings.*;

import javax.xml.bind.JAXBException;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;

import org.xml.sax.SAXException;

import dataStorage.DataHandler;
import dataStorage.DataXML;

import settings.IdManager;

//@author A0105110J
@XmlRootElement
public class Undo extends XMLentity {
	
	private String undoKey;
	private XMLentity undoObject;
	private Class<?> undoClass;
	private String id;
	private int isWrite; //true for undoing a write operation
	private String name = "Undo";

	public Undo(int _UndoType, XMLentity _undoObject, String _rootKey, Class<?> _undoClass) throws TransformerConfigurationException, InstantiationException, IllegalAccessException, JAXBException, ParserConfigurationException, SAXException, IOException, TransformerException 
	{

		this.setWrite(_UndoType);
		// 0 = called by remove
		// 1 = called by write
		// 2 = called by update
		this.setUndoObject(_undoObject);
		//if (_isWrite) {
			this.setUndoId(getUndoObject().getId());
		//}
		
		
		
		this.setUndoKey(_rootKey);
		this.setUndoClass(_undoClass);

		//this.setUndoId(null);
	}
	

	public String getUndoKey() {
		return undoKey;
	}

	public void setUndoKey(String undoKey) {
		this.undoKey = undoKey;
	}

	public XMLentity getUndoObject() {
		return undoObject;
	}

	public void setUndoObject(XMLentity undoObject) {
		this.undoObject = undoObject;
	}

	public Class getUndoClass() {
		return undoClass;
	}

	public void setUndoClass(Class undoClass) {
		this.undoClass = undoClass;
	}

	public int isWrite() {
		return isWrite;
	}

	public void setWrite(int isWrite) {
		this.isWrite = isWrite;
	}
	public String getUndoId() throws TransformerConfigurationException, InstantiationException, IllegalAccessException, JAXBException, ParserConfigurationException, SAXException, IOException, TransformerException {
		
		return id;
	}

	public void setUndoId(String undoId) {
		this.id = undoId;
	}
}
